package ntancnit.app.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

public class User {
	
	private NTANCNITsqlliteHelper helper;
	private SQLiteDatabase db;
	
	public User(Context context) {
		helper = new NTANCNITsqlliteHelper(context);
		db = helper.getWritableDatabase();
	}

	public void close() {
		helper.close();
		db.close();
	}
	
	public static abstract class UserInfomaiton implements BaseColumns{
		private static final String TABLE_NAME = "locationhistory";
		private static final String COLUNM_NAME = "name";
		private static final String DATA_TYPE = " TEXT";
		private static final String CREATE_QUERY = "CREATE TABLE "
				+ UserInfomaiton.TABLE_NAME + " (" + UserInfomaiton.COLUNM_NAME
				+ UserInfomaiton.DATA_TYPE + ")";
	}
	
	
	public class NTANCNITsqlliteHelper extends SQLiteOpenHelper {

		public static final int DATABASE_VERSION = 1;
		public static final String DATABASE_NAME = "FeedReader.db";

		public NTANCNITsqlliteHelper(Context context) {
			super(context, DATABASE_NAME, null, DATABASE_VERSION);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			db.execSQL(UserInfomaiton.CREATE_QUERY);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			onCreate(db);

		}
	}
	
	public void InsertToUser(String user) {
		ContentValues values = new ContentValues();
		values.put(UserInfomaiton.COLUNM_NAME, user);
		db.insert(UserInfomaiton.TABLE_NAME, null, values);
	}

	
	public Cursor SelectFromChat() {
		Cursor c = db.rawQuery("Select * from " + UserInfomaiton.TABLE_NAME, null);
		return c;
	}
	
	public void deleteFromEvent(String where) {
		db.execSQL("delete from "+ UserInfomaiton.TABLE_NAME);
	}
}
